package ssm.another;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * Created by libing on 2016/12/13.
 */
@Controller
@RequestMapping("/login")
public class HomeLoginController {
/*
    @Autowired
    HomeLoginService homeLoginService;

    @RequestMapping("/jump")
    public String jumpToLoginPage()throws Exception{
        //跳转到登录页面
        return "home/index/index";
    }

    @RequestMapping("/login")
    @ResponseBody
    public LoginResult login(Model model, HttpServletRequest request, HttpSession session, User user)throws Exception{

        LoginResult loginResult = new LoginResult();
        if (session.getAttribute("user_phone") != null && session.getAttribute("user_phone").equals(user.getUser_phone())){
            loginResult.setStatus("L000");
            loginResult.setMsg("已经登录，直接跳转");
        }
        if(!CheckUtil.checkMobileFormat(user.getUser_phone())){
            loginResult.setStatus("L001");
            loginResult.setMsg("请输入正确格式的电话号码");
        } else if(homeLoginService.checkExist(user) ==0){
            loginResult.setMsg("L002");
            if (user.getUser_type() == 0) {
                loginResult.setStatus("该手机号码未注册普通用户");
            }else {
                loginResult.setStatus("该手机号码未注册商家用户");
            }
        } else{
            User user1 = homeLoginService.selectPasswordAndKey(user.getUser_phone());
            if(!user1.getUser_password().equals(EncryptUtil.SHA1(user.getUser_password()+EncryptUtil.SHA1(user.getUser_password())))){
                loginResult.setMsg("您输入的密码不正确");
                loginResult.setStatus("L003");
            } else {
                //登录成功
                loginResult.setMsg("L004");
                if (user.getUser_type() == 0) {
                    loginResult.setStatus("用户登录成功");
                }else {
                    loginResult.setStatus("商家登录成功");
                }
                session.setAttribute("user_phone",user.getUser_phone());
                session.setAttribute("user_type",user.getUser_type());
            }
        }
        return loginResult;
    }*/
}
